package com.fortune.service.impl;

import com.fortune.common.redis.RedisClient;
import com.fortune.constants.redis.CacheKeys;
import com.fortune.dao.SalesManDao;
import com.fortune.dto.in.salesMan.SalesManEditDto;
import com.fortune.entity.PhoneAndPassword;
import com.fortune.entity.UserIdAndName;
import com.fortune.service.SalesManService;
import com.fortune.vo.salesMan.LoginSalesManInfo;
import com.fortune.vo.salesMan.SalesManData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SalesManServiceImpl implements SalesManService {
    @Autowired
    private RedisClient redisClient;

    @Autowired
    private SalesManDao salesManDao;

    /*@Override
    public String getRedisKeyByPhone(String phone) {
        String redisCode = redisClient.get(CacheKeys.SALES_MAN_LOGIN_TOKEN, phone);
        if(redisCode == null){
            return "111";
        }
        return redisCode;
    }*/

    /**
     * 查询当前账号是否存在
     * @param phone
     * @return
     */
    @Override
    public PhoneAndPassword finPhoneIsExist(String phone) {
        PhoneAndPassword finPhoneIsExist = salesManDao.finPhoneIsExist(phone);
        return finPhoneIsExist;
    }

    /**
     * 查询密码
     * @param mid
     * @param did
     * @param userId
     * @param phone
     * @return
     */
    @Override
    public String findPasswordByPhone(String did, String userId, String phone) {
        String findPasswordByPhone = salesManDao.findPasswordByPhone(did, userId, phone);
        return findPasswordByPhone;
    }

    /**
     * 查询登陆成功后返回的信息
     * @param phone
     * @return
     */
    @Override
    public LoginSalesManInfo findLoginSalesManInfo(String phone) {
        LoginSalesManInfo findLoginSalesManInfo = salesManDao.findLoginSalesManInfo(phone);
        return findLoginSalesManInfo;
    }

    /**
     * 业务员修改密码
     * @param phone
     * @param newPassword
     * @return
     */
    @Override
    public int editPasswordByPhone(String did, String userId, String phone, String newPassword) {
        int editPasswordByPhone = salesManDao.editPasswordByPhone(did, userId, phone, newPassword);
        return editPasswordByPhone;
    }

    /**
     * 通过业务员手机号查询id
     * @param phone
     * @return
     */
    @Override
    public String findUserIdByPhone(String phone) {
        String findUserIdByPhone = salesManDao.findUserIdByPhone(phone);
        return findUserIdByPhone;
    }

    /**
     * 通过业务员id修改业务员个人资料
     * @param salesManEditDto
     * @param userId
     * @return
     */
    @Override
    public int editSalesmanEditInfor(String did, SalesManEditDto salesManEditDto, String userId) {
        int editSalesmanEditInfor = salesManDao.editSalesmanEditInfor(did, salesManEditDto, userId);
        return editSalesmanEditInfor;
    }

    /**
     * 业务员重置密码
     * @param phone
     * @param password
     * @return
     */
    @Override
    public int editResetPassword(String phone, String password) {
        int editResetPassword = salesManDao.editResetPassword(phone, password);
        return editResetPassword;
    }

    /**
     * 查询业务员id
     * @param phone
     * @return
     */
    @Override
    public UserIdAndName findDUserId(String userId,String did,String phone) {
        UserIdAndName findDUserId = salesManDao.findDUserId(userId,did,phone);
        return findDUserId;
    }

    /**
     * 查询业务员每个月的销售目标总数
     * @param did
     * @return
     */
    @Override
    public String findTargetById(String userId, String did) {
        String findTargetById = salesManDao.findTargetById(userId, did);
        return findTargetById;
    }

    /**
     * 查询业务员完成目标总数
     * @param id
     * @param did
     * @return
     */
    @Override
    public String findCompleted(String id, String did) {
        String findCompleted = salesManDao.findCompleted(id, did);
        return findCompleted;
    }

    /**
     * 个人资料
     * @param did
     * @param userId
     * @return
     */
    @Override
    public SalesManData findSalesManData(String did, String userId) {
        return salesManDao.findSalesManData(did, userId);
    }
}
